package com.liuluo.homework1.controller;

import com.liuluo.homework1.entity.User;
import com.liuluo.homework1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/user")
@CrossOrigin("*")
public class UserController {
    @Autowired
    private UserService userService;
//添加
    @PostMapping("/add")
    public Boolean add(@RequestBody User user) {
        return userService.save(user);
    }
//删除
    @DeleteMapping("/delete")
    public Boolean delete(@RequestBody User user) {
        return userService.removeById(user.getId());
    }
//修改
    @PutMapping("/update")
    public Boolean update(@RequestBody User user) {
        return userService.updateById(user);
    }
//查询
    @GetMapping("/get")
    public User get(@RequestParam int id) {
        return userService.getById(id);
    }
}
